package com.hxkj.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author Mrmas
 * @create 2018-06-07 19:26
 * @desc
 **/
@Configuration
public class HttpClientRestConfig {

    @Bean
    public SimpleClientHttpRequestFactory clientHttpRequestFactory() {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(1000);// 设置超时
        requestFactory.setReadTimeout(1000);
        return requestFactory;
    }

    @Bean
    public RestTemplate restTemplate() {

        return new RestTemplate(clientHttpRequestFactory());
    }
}
